# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_google_googleapis_imports//:imports.bzl", "cc_proto_library")
load("//gutil/gutil/embed_data:build_defs.bzl", "cc_embed_data")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

proto_library(
    name = "p4info_verification_schema_proto",
    srcs = ["p4info_verification_schema.proto"],
    deps = ["//p4_pdpi:ir_proto"],
)

cc_proto_library(
    name = "p4info_verification_schema_cc_proto",
    deps = ["p4info_verification_schema_proto"],
)

cc_embed_data(
    name = "p4info_verification_schema_embed",
    srcs = ["p4info_verification_schema.pb.txt"],
    cc_file_output = "p4info_verification_schema_embed.cc",
    cpp_namespace = "p4rt_app",
    flatten = True,
    h_file_output = "p4info_verification_schema_embed.h",
)

cc_library(
    name = "p4info_verification_schema",
    srcs = ["p4info_verification_schema.cc"],
    hdrs = ["p4info_verification_schema.h"],
    deps = [
        "p4info_verification_schema_cc_proto",
        "p4info_verification_schema_embed",
        "//gutil/gutil:collections",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/utils:table_utility",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "p4info_verification_schema_test",
    srcs = ["p4info_verification_schema_test.cc"],
    deps = [
        ":p4info_verification_schema",
        ":p4info_verification_schema_cc_proto",
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/utils:ir_builder",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "p4info_verification",
    srcs = ["p4info_verification.cc"],
    hdrs = ["p4info_verification.h"],
    deps = [
        ":p4info_verification_schema",
        ":p4info_verification_schema_cc_proto",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic:app_db_acl_def_table_manager",
        "//p4rt_app/sonic:hashing",
        "//p4rt_app/utils:status_utility",
        "//p4rt_app/utils:table_utility",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:cord",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "p4info_verification_test",
    srcs = ["p4info_verification_test.cc"],
    deps = [
        ":p4info_verification",
        "//gutil/gutil:proto",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/utils:status_utility",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "p4runtime_impl",
    srcs = ["p4runtime_impl.cc"],
    hdrs = ["p4runtime_impl.h"],
    deps = [
        ":ir_translation",
        ":p4info_reconcile",
        ":p4info_verification",
        ":p4runtime_read",
        ":packetio_helpers",
	":queue_translator",
        ":resource_utilization",
        ":sdn_controller_manager",
        "//gutil/gutil:collections",
        "//gutil/gutil:io",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi:entity_keys",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:translation_options",
        "//p4rt_app/sonic:app_db_acl_def_table_manager",
        "//p4rt_app/sonic:app_db_manager",
        "//p4rt_app/sonic:hashing",
        "//p4rt_app/sonic:packet_replication_entry_translation",
        "//p4rt_app/sonic:packetio_interface",
        "//p4rt_app/sonic:redis_connections",
        "//p4rt_app/sonic:response_handler",
        "//p4rt_app/sonic:state_verification",
        "//p4rt_app/sonic:vrf_entry_translation",
        "//p4rt_app/sonic/adapters:table_adapter",
        "//p4rt_app/sonic/adapters:warm_boot_state_adapter",
        "//p4rt_app/utils:event_data_tracker",
        "//p4rt_app/utils:status_utility",
        "//p4rt_app/utils:table_utility",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4_constraints//p4_constraints/backend:constraint_info",
        "@com_github_p4lang_p4_constraints//p4_constraints/backend:interpreter",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_googleapis//google/rpc:code_cc_proto",
        "@com_google_protobuf//:protobuf",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_library(
    name = "mock_p4runtime_impl",
    testonly = True,
    hdrs = ["mock_p4runtime_impl.h"],
    deps = [
        ":p4runtime_impl",
	":queue_translator",
	"@com_github_grpc_grpc//:grpc++",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_googletest//:gtest",
    ],
)

cc_library(
    name = "p4runtime_read",
    srcs = ["p4runtime_read.cc"],
    hdrs = ["p4runtime_read.h"],
    deps = [
        ":ir_translation",
        ":queue_translator",
        "//gutil/gutil:status",
        "//p4_pdpi:entity_keys",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic:app_db_manager",
        "//p4rt_app/sonic:redis_connections",
        "//p4rt_app/utils:table_utility",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "packetio_helpers",
    srcs = ["packetio_helpers.cc"],
    hdrs = ["packetio_helpers.h"],
    deps = [
        ":ir_translation",
        "//gutil/gutil:status",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/sonic:packetio_impl",
        "//p4rt_app/sonic:packetio_interface",
        "//sai_p4/fixed:p4_ids",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@sonic_swss_common//:common",
    ],
)

cc_test(
    name = "packetio_helpers_test",
    srcs = ["packetio_helpers_test.cc"],
    deps = [
        ":p4info_verification",
        ":packetio_helpers",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/sonic:packetio_impl",
        "//p4rt_app/sonic:packetio_port",
        "//p4rt_app/sonic/adapters:mock_system_call_adapter",
        "//sai_p4/fixed:p4_ids",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
        "@sonic_swss_common//:common",
    ],
)

cc_library(
    name = "ir_translation",
    srcs = ["ir_translation.cc"],
    hdrs = ["ir_translation.h"],
    deps = [
        ":queue_translator",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:translation_options",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/utils:annotation_parser",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "ir_translation_test",
    srcs = ["ir_translation_test.cc"],
    deps = [
        ":ir_translation",
        ":queue_translator",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/utils:ir_builder",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@boost//:bimap",
        "@boost//:graph",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "sdn_controller_manager",
    srcs = ["sdn_controller_manager.cc"],
    hdrs = ["sdn_controller_manager.h"],
    deps = [
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//sai_p4/fixed:p4_roles",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/numeric:int128",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:optional",
    ],
)

cc_library(
    name = "resource_utilization",
    srcs = ["resource_utilization.cc"],
    hdrs = ["resource_utilization.h"],
    deps = [
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//p4_pdpi:entity_keys",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic:app_db_manager",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "resource_utilization_test",
    srcs = ["resource_utilization_test.cc"],
    deps = [
        ":resource_utilization",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:entity_keys",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic:app_db_manager",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "queue_translator",
    srcs = ["queue_translator.cc"],
    hdrs = ["queue_translator.h"],
    deps = [
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "queue_translator_test",
    srcs = ["queue_translator_test.cc"],
    deps = [
        ":queue_translator",
        "//gutil/gutil:status_matchers",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "p4info_reconcile",
    srcs = ["p4info_reconcile.cc"],
    hdrs = ["p4info_reconcile.h"],
    deps = [
        ":resource_utilization",
        "//gutil/gutil:collections",
        "//gutil/gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic:app_db_acl_def_table_manager",
        "//p4rt_app/sonic:hashing",
        "//p4rt_app/sonic:swss_utils",
        "//p4rt_app/utils:table_utility",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "p4info_reconcile_test",
    srcs = ["p4info_reconcile_test.cc"],
    deps = [
        ":p4info_reconcile",
        ":resource_utilization",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/utils:ir_builder",
        "//p4rt_app/utils:table_utility",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)
